<?php


namespace App\Libraries\CustomsBills\Data\CEB311Message;


use App\Libraries\CustomsBills\Assert;

class OrderList
{
    /**
     * @var int
     * @author luffyzhao@vip.126.com
     */
    protected $gnum;
    /**
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $itemName;
    /**
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $gModel;
    /**
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $country;
    /**
     * @var string
     * @author luffyzhao@vip.126.com
     */
    protected $unit;
    /**
     * @var float
     * @author luffyzhao@vip.126.com
     */
    protected $price;
    /**
     * @var int
     * @author luffyzhao@vip.126.com
     */
    protected $qty;

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getItemName(): string
    {
        Assert::notEmpty($this->itemName, "商品名称 不能为空");
        Assert::maxLength($this->itemName, 250, "商品名称 最大长度为 200 个字符");
        return $this->itemName;
    }

    /**
     * @param string $itemName
     * @author luffyzhao@vip.126.com
     */
    public function setItemName(string $itemName): void
    {
        $this->itemName = $itemName;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getGModel(): string
    {
        Assert::notEmpty($this->gModel, "商品名称 不能为空");
        Assert::maxLength($this->gModel, 510, "商品名称 最大长度为 510 个字符");
        return $this->gModel;
    }

    /**
     * @param string $gModel
     * @author luffyzhao@vip.126.com
     */
    public function setGModel(string $gModel): void
    {
        $this->gModel = $gModel;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getCountry(): string
    {
        Assert::notEmpty($this->country, "国别代码 不能为空");
        Assert::maxLength($this->country, 3, "国别代码 最大长度为 3 个字符");
        return $this->country;
    }

    /**
     * @param string $country
     * @author luffyzhao@vip.126.com
     */
    public function setCountry(string $country): void
    {
        $this->country = $country;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function getUnit(): string
    {
        Assert::notEmpty($this->unit, "申报单位 不能为空");
        Assert::maxLength($this->unit, 3, "申报单位 最大长度为 3 个字符");
        return $this->unit;
    }

    /**
     * @param string $unit
     * @author luffyzhao@vip.126.com
     */
    public function setUnit(string $unit): void
    {
        $this->unit = $unit;
    }

    /**
     * @return float
     * @author luffyzhao@vip.126.com
     */
    public function getPrice(): float
    {
        Assert::floatAndRadixLength($this->price, 19, 5, "单价 格式 N19,5");
        return $this->price;
    }

    /**
     * @param float $price
     * @author luffyzhao@vip.126.com
     */
    public function setPrice(float $price): void
    {
        $this->price = $price;
    }

    /**
     * @return int
     * @author luffyzhao@vip.126.com
     */
    public function getQty(): int
    {
        Assert::integer($this->qty, "数量 格式 N19");
        return $this->qty;
    }

    /**
     * @param int $qty
     * @author luffyzhao@vip.126.com
     */
    public function setQty(int $qty): void
    {
        $this->qty = $qty;
    }

    /**
     * @return float
     * @author luffyzhao@vip.126.com
     */
    public function getTotalPrice(): float
    {
        return $this->qty * $this->price;
    }

    /**
     * @return int
     * @author luffyzhao@vip.126.com
     */
    public function getGnum(): int
    {
        Assert::integer($this->gnum, "数量 格式 N19");
        return $this->gnum;
    }

    /**
     * @param int $gnum
     * @author luffyzhao@vip.126.com
     */
    public function setGnum(int $gnum): void
    {
        $this->gnum = $gnum;
    }

    /**
     * @return string
     * @author luffyzhao@vip.126.com
     */
    public function __toString(): string
    {
        return <<<ORDERLIST
<ceb:OrderList>
    <ceb:gnum>{$this->getGnum()}</ceb:gnum>
    <ceb:itemName>{$this->getItemName()}</ceb:itemName>
    <ceb:gmodel>{$this->getGModel()}</ceb:gmodel>
    <ceb:unit>{$this->getUnit()}</ceb:unit>
    <ceb:qty>{$this->getQty()}</ceb:qty>
    <ceb:price>{$this->getPrice()}</ceb:price>
    <ceb:totalPrice>{$this->getTotalPrice()}</ceb:totalPrice>
    <ceb:currency>142</ceb:currency>
    <ceb:country>{$this->getCountry()}</ceb:country>
</ceb:OrderList>
ORDERLIST;
    }


}